/** @jsxImportSource @emotion/react */
import * as React from "react";
import {RepLink, ReportViewProps,} from "../../common/base";
import {末尾链接,} from "../../common/rarelyVary";
import {CCell, Cell, Embed, RCell, Table, TableBody, TableRow, Text, useTheme} from "customize-easy-ui-component";
import {useRepMenuDirItems} from "../../hook/useMainRepUrlOr";
import {ContainerInfoVw} from "./ContainerInfo";
import {ReportFirstPageHeadCyMa} from "../../valve/rarelyVary";
import {TwoRaftDeviceInfo} from "../../contain/views";
import {Link as RouterLink} from "../../../routing/Link";
import {config设备概况} from "./orcBase";
import {FadeImage} from "../../../comp/FadeImage";
import Img_TS from "../../../images/TS.png";
import {ManufactCharacterVw} from "./ManufactCharacter";
import {Projects记录} from "./Regular.O-1";
import {useItemsMapPressure} from "../../common/pressure";

export const ReportView: React.FunctionComponent<ReportViewProps> = ({
    repId,   source: orc,  verId,rep,
}) => {
    const theme= useTheme();
    const [mapFxian]=useItemsMapPressure({ projects:orc.Projects });
    const [rootMenu]=useRepMenuDirItems(Projects记录, orc.Projects, `/reportView/${rep?.modeltype}/ver/${verId}/${repId}`);
  return (
    <React.Fragment>
        {rootMenu}
        <div css={{"@media not print": {marginTop: '1rem', marginBottom: '1rem'}}}>
            <CertificatePage orc={orc} rep={rep}/>
            {mapFxian.get('压力管道数据表')?.do &&
                <ManufactCharacterVw orc={orc} rep={rep}/>
            }
            {mapFxian.get('系统内压力容器情况')?.do &&
                <ContainerInfoVw orc={orc} rep={rep}/>
            }
            <RouterLink href={`/report/${rep?.modeltype}/ver/${verId}/${repId}/Conclusion`}>
                <Text variant="h3" css={{marginTop:'1rem',"@media print": {display: 'none'}}}>检验下结论&gt;</Text>
            </RouterLink>
            <RouterLink href={`/report/${rep?.modeltype}/ver/${verId}/${repId}/ProjectList`}>
                <Text variant="h3" css={{marginTop:'1rem',"@media print": {display: 'none'}}}>承压类报告的分项列表&gt;</Text>
            </RouterLink>
        </div>
        {末尾链接({template: rep?.modeltype, verId, repId: repId || ''})}
    </React.Fragment>
  );
}


export const CertificatePage= ({ orc, rep, children} : { orc: any,rep: any,children?: React.ReactNode}
) => {
    const theme= useTheme();
    const callback = () => {
        return <div  css={{"@media print": {height:'100vh', overflowY: 'hidden',} }}>
            { ReportFirstPageHeadCyMa({theme,rep, mbbm:'FJB/RA1206-0-2023',nMa:true}) }
            <div css={{
                "@media print": {
                    display: 'flex',
                    flexDirection: 'column',
                    justifyContent: 'space-around',
                    height: 'calc(100vh - 5rem)',     //剪掉上面头部的高度
                }
            }}>
                <Text variant="h3" css={{textAlign:'center', "@media print": {fontSize: theme.fontSizes[5],},}}>
                   特种设备监督检验证书
                </Text>
                <Text variant="h6" css={{textAlign:'center'}}>（撬装式承压设备系统制造）</Text>
                <div>
                    <div css={{display: 'flex',justifyContent: 'space-between',}}>
                        &nbsp;
                        <Text css={{display: 'flex',flexDirection: 'row-reverse',marginRight: '2rem'
                        }}>证书编号：{rep.isp?.no}</Text>
                    </div>
                    <Table fixed={ ["14.1%", "38%", "14.1%", "%"] }  css={ {borderCollapse: 'collapse',
                        "@media print": {height:'72vh',} } } tight  miniw={800}>
                        <TableBody>
                            <TwoRaftDeviceInfo orc={orc} rep={rep} config={config设备概况} tag='Survey'/>
                            <RepLink rep={rep} tag='Conclusion'>
                                <TableRow>
                                    <CCell colSpan={4}>
                                        <Table  fixed={ ["24%", "39%", "6%", "%"] }
                                                css={ {borderCollapse: 'collapse', "@media print": {height:'fill-available'},} }  tight  miniw={800}>
                                            <TableBody>
                                                {orc?.检验结论==='符合' && <TableRow>
                                                    <Cell css={{border:'none',textIndent:'2rem',}} colSpan={4}>
                                                        <Text css={{minHeight:'5rem',lineHeight: 1.9,textIndent:'2rem'}}>
                                                        按照《中华人民共和国特种设备安全法》、《特种设备安全监察条例》的规定，该台撬装式承压设备系统产品经本机构实施监督检验，安全性能
                                                            符合 《压力管道安全技术监察规程-工业管道》《固定式压力容器安全技术监察规程》的要求。
                                                            <Text css={{display:'block',textIndent:'2rem'}}>特发此证书。</Text>
                                                        </Text>
                                                    </Cell></TableRow>
                                                }
                                                <TableRow>
                                                    <Cell css={{border:'none'}} colSpan={4}>
                                                        <Embed css={{width: "96px",margin: "auto",top: '-0.15rem'}} width={43} height={43}>
                                                            <FadeImage src={Img_TS}/>
                                                        </Embed>
                                                    </Cell>
                                                </TableRow>
                                                <TableRow css={{"@media print": {height:'3rem'} }}>
                                                    <RCell css={{border:'none'}}>监督检验人员：</RCell>
                                                    <Cell css={{border:'none'}}>机erter</Cell>
                                                    <RCell css={{border:'none'}}>日期：</RCell>
                                                    <Cell css={{border:'none'}}></Cell>
                                                </TableRow>
                                                <TableRow css={{"@media print": {height:'3rem'} }}>
                                                    <RCell css={{border:'none'}}>审   核：</RCell>
                                                    <Cell css={{border:'none'}}></Cell>
                                                    <RCell css={{border:'none'}}>日期：</RCell>
                                                    <Cell css={{border:'none'}}>2024-04-10</Cell>
                                                </TableRow>
                                                <TableRow css={{"@media print": {height:'3rem'} }}>
                                                    <RCell css={{border:'none'}}>批   准：</RCell>
                                                    <Cell css={{border:'none'}}></Cell>
                                                    <RCell css={{border:'none'}}>日期：</RCell>
                                                    <Cell css={{border:'none'}}>2024-04-10</Cell>
                                                </TableRow>
                                                <TableRow>
                                                    <RCell css={{border:'none'}}>监督检验机构：</RCell>
                                                    <Cell colSpan={2} css={{border:'none'}}>{rep?.isp?.ispu?.name}</Cell>
                                                    <CCell css={{border:'none'}}>（监督检验机构检验专用章）</CCell>
                                                </TableRow>
                                                <TableRow css={{"@media print": {height:'fill-available'} }}>
                                                    <RCell  css={{border:'none'}}>检验机构核准证号：</RCell>
                                                    <Cell  colSpan={2} css={{border:'none'}}>{rep?.isp?.ispu?.agency?.apno}</Cell>
                                                    <CCell css={{border:'none'}}>2024-04-10</CCell>
                                                </TableRow>
                                            </TableBody>
                                        </Table>
                                    </CCell>
                                </TableRow>
                            </RepLink>
                        </TableBody>
                    </Table>
                </div>
                <Text css={{fontSize:'0.8rem'}}>注：本证书一式三份，一份监督检验机构存档，两份送制造单位，其中一份由制造单位随产品出厂资料交付。
                </Text>
            </div>
        </div>
    }
    return <>
        <div id="Certificate"/>
        {callback()}
    </>;
};
